package com.dhemery.mack.adapters.tests;

import static org.junit.Assert.*;

import org.eclipse.jface.resource.ImageDescriptor;
import org.junit.Before;
import org.junit.Test;

import com.dhemery.mack.adapters.ImageDescriptorSource;
import com.dhemery.mack.adapters.ImageKey;
import com.dhemery.mack.adapters.NodeImageDescriptorFactory;
import com.dhemery.mack.model.Folder;
import com.dhemery.mack.model.Node;
import com.dhemery.mack.model.Page;
import com.dhemery.mack.model.Project;
import com.dhemery.mack.model.Session;

public class NodeImageDescriptorFactoryTests {
	private ImageDescriptorSource source;
	
	@Before
	public void setUp() {
		source = new FakeImagePathImageDescriptorSource();
	}

	@Test
	public void pageImageKey() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageKey imageKey = ImageKey.PAGE;
		ImageDescriptor expected = new FakeImageDescriptor(imageKey.getImagePath());
		ImageDescriptor actual = factory.createImageDescriptor(imageKey);
		assertEquals(expected, actual);
	}

	@Test
	public void folderImageKey() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageKey imageKey = ImageKey.FOLDER;
		ImageDescriptor expected = new FakeImageDescriptor(imageKey.getImagePath());
		ImageDescriptor actual = factory.createImageDescriptor(imageKey);
		assertEquals(expected, actual);
	}

	@Test
	public void projectImageKey() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageKey imageKey = ImageKey.PROJECT;
		ImageDescriptor expected = new FakeImageDescriptor(imageKey.getImagePath());
		ImageDescriptor actual = factory.createImageDescriptor(imageKey);
		assertEquals(expected, actual);
	}

	@Test
	public void sessionImageKey() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageKey imageKey = ImageKey.SESSION;
		ImageDescriptor expected = new FakeImageDescriptor(imageKey.getImagePath());
		ImageDescriptor actual = factory.createImageDescriptor(imageKey);
		assertEquals(expected, actual);
	}

	@Test
	public void pageNode() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageDescriptor expected = factory.createImageDescriptor(ImageKey.PAGE);
		ImageDescriptor actual = factory.createImageDescriptor(new Page());
		assertEquals(expected, actual);
	}

	@Test
	public void folderNode() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageDescriptor expected = factory.createImageDescriptor(ImageKey.FOLDER);
		ImageDescriptor actual = factory.createImageDescriptor(new Folder());
		assertEquals(expected, actual);
	}

	@Test
	public void projectNode() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageDescriptor expected = factory.createImageDescriptor(ImageKey.PROJECT);
		ImageDescriptor actual = factory.createImageDescriptor(new Project());
		assertEquals(expected, actual);
	}

	@Test
	public void sessionNode() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageDescriptor expected = factory.createImageDescriptor(ImageKey.SESSION);
		ImageDescriptor actual = factory.createImageDescriptor(new Session());
		assertEquals(expected, actual);
	}

	@Test
	public void missingImageDescriptorForNodeObject() {
		NodeImageDescriptorFactory factory = new NodeImageDescriptorFactory(source);
		ImageDescriptor expected = ImageDescriptor.getMissingImageDescriptor();
		ImageDescriptor actual = factory.createImageDescriptor(new Node(null));
		assertEquals(expected, actual);
	}
}
